#include "PrecompiledHeaderRenderer_OpenGL.h"
#include "PolygonWrapper.h"

/*--------------------------------------------------------------------------*/
GLboolean PolygonWrapper::_CullFaceEnabled = GL_TRUE;
GLenum PolygonWrapper::_CullFaceMode = GL_BACK;
GLenum PolygonWrapper::_FrontFace = GL_CCW;
GLenum PolygonWrapper::_PolygonModeFront = GL_FILL;
GLenum PolygonWrapper::_PolygonModeBack = GL_FILL;
/*--------------------------------------------------------------------------*/

PolygonWrapper::PolygonWrapper(void)
{
	if (_CullFaceEnabled)
	{
		glEnable(GL_CULL_FACE);
	}
	else
	{
		glDisable(GL_CULL_FACE);
	}

	glCullFace(_CullFaceMode);
	glFrontFace(_FrontFace);
	glPolygonMode(GL_FRONT, _PolygonModeFront);
	glPolygonMode(GL_BACK, _PolygonModeBack);
}

/*--------------------------------------------------------------------------*/

PolygonWrapper::~PolygonWrapper(void)
{
}

/*--------------------------------------------------------------------------*/

void PolygonWrapper::CullFaceEnabled(GLboolean v1)
{
	if (v1 != _CullFaceEnabled)
	{
		_CullFaceEnabled = v1;

		if (v1)
		{
			glEnable(GL_CULL_FACE);
		}
		else
		{
			glDisable(GL_CULL_FACE);
		}
	}
}

/*--------------------------------------------------------------------------*/

void PolygonWrapper::CullFaceMode(GLenum v1)
{
	if (v1 != _CullFaceMode)
	{
		_CullFaceMode = v1;
		glCullFace(_CullFaceMode);
	}
}

/*--------------------------------------------------------------------------*/

void PolygonWrapper::FrontFace(GLenum f)
{
	if (f != _FrontFace)
	{
		_FrontFace = f;
		glFrontFace(_FrontFace);
	}
}

/*--------------------------------------------------------------------------*/

void PolygonWrapper::PolygonMode(GLenum v1, GLenum v2)
{
	GLenum front = v1, back = v2;

	if (v2 == v1 && (v1 != _PolygonModeFront || v2 != _PolygonModeBack))
	{
		_PolygonModeFront = v1;
		_PolygonModeBack = v2;
		glPolygonMode(GL_FRONT_AND_BACK, v1);
	}
	else if (v1 != _PolygonModeFront)
	{
		_PolygonModeFront = v1;
		glPolygonMode(GL_FRONT, v1);
	}
	else if (v2 != _PolygonModeBack)
	{
		_PolygonModeBack = v2;
		glPolygonMode(GL_BACK, v2);
	}
}

/*--------------------------------------------------------------------------*/